package pingan.com.quarter_hour.acyivity.login;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import pingan.com.quarter_hour.R;
import pingan.com.quarter_hour.bean.RegisteredBean;
import pingan.com.quarter_hour.presenter.UserPresenter;
import pingan.com.quarter_hour.view.IView;

public class RegisteredActivity extends AppCompatActivity implements View.OnClickListener,IView {

    private static final String TAG = "RegisteredActivity";
    @BindView(R.id.zhcue)
    TextView zhcue;
    @BindView(R.id.z_myname)
    EditText zMyname;
    @BindView(R.id.z_mypassword)
    EditText zMypassword;
    @BindView(R.id.z_login)
    TextView zLogin;
    private UserPresenter userPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registered);
        ButterKnife.bind(this);

        zhcue.setOnClickListener(this);
        zLogin.setOnClickListener(this);

        userPresenter = new UserPresenter();
        userPresenter.attachView(this);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.zhcue:
                Intent intent = new Intent(RegisteredActivity.this, ZhuCeActivity.class);
                startActivity(intent);
                finish();
                break;
            case R.id.z_login:


                String trim = zMyname.getText().toString().trim();
                String pass = zMypassword.getText().toString().trim();

                HashMap<String, String> map = new HashMap<>();
                map.put("mobile", trim);
                map.put("password", pass);
                //   https://www.zhaoapi.cn/quarter/register?mobile=13161666667&password=123123
                userPresenter.getRegisteredBean(" https://www.zhaoapi.cn/", map);
                Toast.makeText(RegisteredActivity.this, "点击了", Toast.LENGTH_SHORT).show();
                break;
        }
    }


    @Override
    public void success(Object o) {
        RegisteredBean news= (RegisteredBean) o;
       if(news!=null){
           Log.i(TAG, "注册: "+news.getMsg());
       }
           
    }

    @Override
    public void Failes(Exception e) {

    }
}
